<?php

// This file return single pangram as image

// set the content-type
if (@$_REQUEST['debug']=='true')
  header("Content-type: text/html");
else
  header("Content-type: image/png");

/*
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

// get input params
$size = 1*@$_REQUEST['size'];
if ($size < 1) $size=1;
if ($size > 150) $size=150;
$text = substr(@$_REQUEST['text'],0,500);

// offset
$ox = 1*@$_REQUEST['ox'];
$oy = 1*@$_REQUEST['oy'];

// replace path by your own font path (if OS cache it then change the name, also use path that apache/php can read)
$font = 'osifont.ttf';
#$font = '/var/www/osifont/osifont.ttf';
#$font = 'osifont-2010-11-24.ttf';
#$font = '/usr/share/fonts/truetype/msttcorefonts/Arial.ttf';
#$font = '/var/www/osifont/osifont.ttf';


// construct text and get bounding box
$box = @imagettfbbox($size,0,$font,$text);
if (!$box)
  $font = "/var/www/osifont/$font";
  $box = @imagettfbbox($size,0,$font,$text);
if (!$box) {
  header('Content-Type: text/plain');
  die("cannot load $font, box=$box, perhaps it must be in /usr/share/somewhere or /var/www/... or sometimes it needs full path");
}

// create the image
$w = $box[2]-$box[0];
$h = $box[3]-$box[5]+2*4;
$w = $w + $h;
//echo "$w / $h ";
//return;
$im = imagecreatetruecolor($w,$h);

// create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, $w-1, $h-1, $white);
if (@$_REQUEST['frame'])
	imagerectangle($im,0,0,$w-1,$h-1,$grey);

// print text itself
imagettftext($im, $size, 0, $ox+$h/2, $oy-$box[5]+4, $black, $font, $text);

// print image content
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>

